// pages/order/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:0,
    page:1,
    status:0,
    lastpage:0,
    listData:[],
    user_info:{},
    money:0,
    freeze_money:0,
    income:0,
    serviceProviderCount:0,
    storeCount:0,
    listData:[],
    loaded:0,
    page:1,
    statisticsBasicInfo:{
      order_amount:0.00,
      order_count:0,
    }
  },

  init:function(){
    var that = this;
    app.api("apiv2/user/getStoreCount", function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      that.setData({
        storeCount: res.data
      });
    });
    app.api("apiv2/user/getServiceProviderCount", function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      that.setData({
        serviceProviderCount: res.data
      });
    });

    app.api("apiv2/user/serviceMoney", function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      that.setData({
        money: res.data.money,
        freeze_money: res.data.freeze_money,
        income: Number(res.data.freeze_money) + Number(res.data.money)
      });
    });

    app.api("apiv2/service_provider_order/statisticsBasicInfo", { type: "month" }, function (res) {
      var data = res.data;
      that.setData({ statisticsBasicInfo: data });

    })
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     
    if (options.status){
      this.data.status = options.status;
      this.setData({ status: options.status });
    }
    app.getUserInfo((user_info)=>{
      this.setData({ user_info: user_info});
      this.init();
    })
    this.getrecommend();
    
  },
  getrecommend() {
    var that = this;
    var page = that.data.page;
    if ( that.data.lastpage == 1) {
      return;
    }
    that.data.loaded = 1;
    //console.log(event_type);
    app.api("sns/topic/list", {
      page: page,
      pid2: 0,
      pid: 100,
      limit: 10,
      order: 'id desc',
    }, function (res) {
     
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      if (res.data.list.length > 0) {
        that.setData({ listData: that.data.listData.concat(res.data.list) });
      } else {
        that.data.lastpage = 1;
      }
      
      that.data.loading = 0;
      that.data.page++;
    })
  },
  
  addMch:function(){
    var url = "/pages/webview/index?url=" + encodeURIComponent("https://wap.bestsmartbee.com/pages/mch/#/store_id/0/pid/" + this.data.user_info.user_id);
     wx.navigateTo({
       url: url,
     })
  },
  addMchMyBlank: function () {
    // var url = "/pages/webview/index?url=" + encodeURIComponent("https://wap.bestsmartbee.com/pages/mch_mybank/#/store_id/0/pid/" + this.data.user_info.user_id);
    // wx.navigateTo({
    //   url: url,
    // })
    wx.navigateTo({
      url: "/pages/mch/mybank_choose",
    })
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.init();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
    this.getrecommend();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})